//打开迷你播放器
function openMiniPlayer(info)
{
	var url = "player.html#" + info.selectionText;
	if (localStorage["showSelectionContext_Type"] == 2)
	{
		chrome.windows.create({url: url, width: 285, height:83 ,type: 'popup'});
	}
	else
	{
		var notification = webkitNotifications.createHTMLNotification(url);
		/*this.notification.addEventListener('close', function(){
			notification = null;
		});*/
		notification.show();
	}
}

//右键打开亦歌播放器
function openPlayerTag()
{
	var mainUrl = chrome.extension.getURL('main.html');  //打开地址
	   //判断是否已经打开
	   chrome.tabs.getAllInWindow(undefined, function(tabs) {
		   for (var i = 0, tab; tab = tabs[i]; i++) {
			   if (tab.url && tab.url == mainUrl) {
				   chrome.tabs.update(tab.id, {selected: true});
				   return;
			   }
		   }
		   chrome.tabs.create({url: mainUrl});
	   });
}

//创建右键菜单函数
function createContextMenus()
{
	if (JSON.parse(localStorage["showPageContext"]))
	    localStorage["showPageContext_id"] = chrome.contextMenus.create({title: "打开亦歌播放器", contexts:["page"], onclick: openPlayerTag}); 
	if (JSON.parse(localStorage["showSelectionContext"]))
	    localStorage["showSelectionContext_id"] = chrome.contextMenus.create({title: "在亦歌中播放", contexts:["selection"], onclick: openMiniPlayer});
} 